<template>
	<view class="container">
		<view class="porson-pagebg">
			<image src="../../static/img_my_bg.png" mode="widthFix"></image>
		</view>
		<view class="porson-pageinfo">
			<view class="porson-pageinfo-big">
				<view class="porson-pageinfo-head">
					<view class="porson-pageinfo-headImg">
						<view class="porson-pageinfo-headImgnav">
							<image :src="userinfo.avatar" mode="widthFix"></image>
						</view>
					</view>
					<view class="porson-pageinfo-headtxt">
						<text>{{userinfo.nickname}}</text>
						<text @click="lookuser">查看并编辑个人资料</text>
					</view>
				</view>
				<view class="porson-pageinfo-head-logout" @click="loginout">
					<image src="../../static/ic_out.png" mode=""></image>
				</view>
			</view>
			<view class="porson-pageinfo-part">
				<view class="porson-pageinfo-partItem" @click="bindpage(0)">
					<view class="porson-pageinfo-partItemImg">
						<image src="../../static/ic_mycoll.png" mode="widthFix"></image>
					</view>
					<text>我的收藏</text>
				</view>
				<view class="porson-pageinfo-partItem" @click="bindpage(1)">
					<view class="porson-pageinfo-partItemImg">
						<image src="../../static/ic_jiuzhenren.png" mode="widthFix"></image>
					</view>
					<text>就诊人管理</text>
				</view>
			</view>
		</view>
		
		
		
		
		<view class="porson-pagebox">
			<view class="porson-pageyuyue">
				<view class="porson-pageyuyue-t">
					<view class="porson-pageyuyue-tl">
						<view class="porson-pageyuyue-tlImg">
							<image src="../../static/ic_time.png" mode="widthFix"></image>
						</view>
						<text>最近预约</text>
					</view>
					<view class="porson-pageyuyue-tr" @click="orderAll">
						<text>全部预约</text>
						<view class="porson-pageyuyue-trImg">
							<image src="../../static/icon_right_white.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
				<view class="yy-su-con" v-if="latelyinfo.id">
					<view class="porson-pageyuyue-dai">
						<image src="../../ic_daijiuzhen.png" mode="widthFix"></image>
					</view>
					<view class="yy-su-con-title">
						<text>预约号</text>
					</view>
					<view class="yy-su-con-num">
						<text class="yy-su-con-num">{{latelyinfo.code}}</text>
					</view>
					<view class="yy-su-con-list">
						<view class="yy-su-con-item">
							<text>候诊时间</text>
							<text class="yy-su-con-Sitem">{{latelyinfo.make_time}}</text>
						</view>
						<view class="yy-su-con-item">
							<text>就诊科室</text>
							<text>{{latelyinfo.department_name}}</text>
						</view>
						<view class="yy-su-con-item">
							<text>就诊医生</text>
							<text>{{latelyinfo.nickname}}</text>
						</view>
					</view>
				</view>
				<view class="porson-pageyuyue-c" v-else>
					<view class="porson-pageyuyue-cNull">
						<image src="../../static/ic_wateing.png" mode="widthFix"></image>
					</view>
					<text>您还没有相关预约</text>
				</view>
			</view>
		</view>
		<Patient-footer-bar :selected="4"></Patient-footer-bar>
	</view>
</template>

<script>
	import app from '../../App.vue';
	export default{
		data(){
			return{
				detailList:[],
				msgId:'',
				userinfo:'',
				latelyinfo:''
			}
		},
		onLoad(options) {
			this.msgId = options.id
			// this.getdetailList()
			this.getuserinfo()
			this.getlatelybook()
		},
		onShow() {
			
		},
		methods: {
			bindpage(pageId){						//收藏或就诊人
				let that = this
				if(pageId == 0){
					uni.showLoading({
						title:'加载中',
						success() {
							setTimeout(function(){
								uni.navigateTo({
									url:'/pages/person/coll'
								})
							},1300)
						}
					})
				}else{
					uni.showLoading({
						title:'加载中',
						success() {
							setTimeout(function(){
								uni.navigateTo({
									url:'/pages/person/manage'
								})
							},1300)
						}
					})
				}
			},
			getuserinfo(){			//个人信息
				let that = this
				app.post('api/user/index','GET').then(res=>{
					if(res.code == 1){
						console.log(res)
						that.userinfo = res.data
					}
				})
			},
			lookuser(){				//跳转个人信息
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/person/ziliao'
							})
						},1300)
					}
				})
			},
			getlatelybook(){			//最近预约
				let that = this,
				data = {
					
				}
				app.post('api/order/getNewOrder',data).then(res=>{
					if(res.code == 1){
						console.log(res)
						that.latelyinfo = res.data
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			orderAll(){					//全部预约
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/person/yuyue'
							})
						},1300)
					}
				})
			},
			loginout(){
				uni.showModal({
					content:'确定退出登录',
					success(res) {
						if(res.confirm){
							app.post('api/user/logout','GET').then(res=>{
								if(res.code == 1){
									uni.showLoading({
										title:'加载中',
										success() {
											setTimeout(function(){
												uni.hideLoading()
												uni.clearStorageSync()
												uni.navigateTo({
													url:'/pages/login/login'
												})
											},1300)
										}
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/person.css");
</style>
